import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * 需要把后面的路径改成自己组件的地址 参照数据库里的component字段
 component: () => import('@/views/dashboard/index'),
 */

export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/userInfo',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/',
        name: 'IconIndex',
        component: () => import('@/views/dashboard/index'),
        meta: { title: '个人中心', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',

    children: [
      {
        path: '/',
        name: 'home',
        component: () => import('@/views/index'),
        meta: { title: '首页', icon: 'dashboard' }
      }
    ]
  },

  {
    path: '/system',
    component: Layout,
    redirect: '/example/table',
    name: 'System',
    meta: { title: '系统管理', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'user',
        name: 'User',
        component: () => import('@/views/system/user/index'),
        meta: { title: '用户管理', icon: 'table' }
      },
      {
        path: '/system/user/role/:userId',
        name: 'userRole',
        hidden: true,
        props: true,
        component: () => import('@/views/system/user/role'),
        meta: { title: '分配角色', icon: 'tree' }
      },
      {
        path: 'role',
        name: 'Role',
        component: () => import('@/views/system/role/index'),
        meta: { title: '角色管理', icon: 'tree' }
      },
      {
        path: 'menu',
        name: 'Menu',
        component: () => import('@/views/system/menu/index'),
        meta: { title: '菜单管理', icon: 'tree' }
      },
      {
        path: 'dept',
        name: 'Dept',
        component: () => import('@/views/system/dept/index'),
        meta: { title: '部门管理', icon: 'tree' }
      },
      {
        path: 'post',
        name: 'Post',
        component: () => import('@/views/system/post/index'),
        meta: { title: '岗位管理', icon: 'tree' }
      },
      {
        path: 'dict',
        name: 'Dict',
        component: () => import('@/views/system/dict/index'),
        meta: { title: '字典管理', icon: 'tree' }
      },
      {
        path: '/system/dict-data/index/:dictId(\\d+)',
        name: 'Data',
        hidden: true,
        component: () => import('@/views/system/dict/data'),
        meta: { title: '字典数据', icon: 'tree' }
      },
      {
        path: 'log',
        name: 'log',
        component: () => import('@/views/nested/index'),
        meta: { title: '日志管理', icon: 'tree' },
        children: [
          {
            path: 'operlog',
            component: () => import('@/views/nested/menu1/index'),
            name: 'Operlog',
            meta: { title: '操作日志', icon: 'log' }
          },
          {
            path: 'logininfor',
            component: () => import('@/views/nested/menu2/index'),
            name: 'Logininfor',
            meta: { title: '登录日志', icon: 'logininfor' }
          }
        ]
      }
    ]
  },

  {
    path: '/monitor',
    component: Layout,
    redirect: '/example/table',
    name: 'Monitor',
    meta: { title: '系统监控', icon: 'el-icon-s-help' },
    children: [
      {
        path: 'online',
        name: 'Online',
        component: () => import('@/views/form/index'),
        meta: { title: '在线用户', icon: 'form' }
      },
      {
        path: 'druid',
        name: 'Druid',
        component: () => import('@/views/form/index'),
        meta: { title: '数据监控', icon: 'form' }
      },
      {
        path: 'server',
        name: 'Server',
        component: () => import('@/views/form/index'),
        meta: { title: '服务监控', icon: 'form' }
      },
      {
        path: 'cache',
        name: 'Cache',
        component: () => import('@/views/form/index'),
        meta: { title: '缓存监控', icon: 'form' }
      }
    ]
  },
  {
    path: '/swagger',
    component: Layout,
    children: [
      {
        path: 'http://localhost:8080/doc.html',
        meta: { title: '系统接口', icon: 'link' }
      }
    ]
  },
  {
    path: '/community',
    component: Layout,
    redirect: '/nested/menu1',
    name: 'Community',
    meta: { title: '社区资产', icon: 'nested' },
    children: [
      {
        path: 'community',
        name: 'Community1',
        component: () => import('@/views/property/community/index'),
        meta: { title: '小区信息', icon: 'form' }
      },
      {
        path: 'building',
        name: 'Building',
        component: () => import('@/views/property/building/index'),
        meta: { title: '楼栋信息', icon: 'form' }
      },
      {
        path: 'unit',
        name: 'Unit',
        component: () => import('@/views/property/unit/index'),
        meta: { title: '单元信息', icon: 'form' }
      },
      {
        path: 'room',
        name: 'Room',
        component: () => import('@/views/property/room/index'),
        meta: { title: '房屋信息', icon: 'form' }
      }
    ]
  },
  {
    path: '/bing',
    component: Layout,
    redirect: '/example/table',
    name: 'Bing',
    meta: { title: '小区管理', icon: 'el-icon-s-grid' },
    children: [
      {
        path: 'owner',
        name: 'Owner',
        component: () => import('@/views/property/owner/index'),
        meta: { title: '业主信息', icon: 'el-icon-user' }
      },
      {
        path: 'ownerRoom',
        name: 'OwnerRoom',
        component: () => import('@/views/property/ownerRoom/index'),
        meta: { title: '业主审核', icon: 'el-icon-s-check' }
      }
    ]
  },
  {
    path: '/interaction',
    component: Layout,
    redirect: '/example/table',
    name: 'Interaction',
    meta: { title: '互动管理', icon: 'el-icon-s-comment' },
    children: [
      {
        path: 'interaction',
        name: 'Interaction1',
        component: () => import('@/views/property/interaction/index'),
        meta: { title: '社区互动', icon: 'form' }
      },
      {
        path: '/',
        name: 'home',
        component: () => import('@/views/index'),
        meta: { title: '互动消息', icon: 'dashboard' }
      }
    ]
  },
  {
    path: '/visitor',
    component: Layout,
    redirect: '/example/table',
    name: 'Visitor',
    meta: { title: '访客管理', icon: 'el-icon-edit-outline' },
    children: [
      {
        path: 'visitor',
        name: 'Visitor1',
        component: () => import('@/views/property/visitor/index'),
        meta: { title: '访客邀请', icon: 'el-icon-s-custom' }
      }
    ]
  },
  {
    path: '/suggest',
    component: Layout,
    redirect: '/example/table',
    name: 'Suggest',
    meta: { title: '投诉管理', icon: 'el-icon-monitor' },
    children: [
      {
        path: 'suggest',
        name: 'Suggest1',
        component: () => import('@/views/property/suggest/index'),
        meta: { title: '投诉建议', icon: 'el-icon-document' }
      },
      {
        path: 'suggest',
        name: 'Suggest1',
        component: () => import('@/views/property/suggest/index'),
        meta: { title: '投诉人员', icon: 'form' }
      }
    ]
  },
  {
    path: '/repair',
    component: Layout,
    redirect: '/example/table',
    name: 'repair',
    meta: { title: '报修管理', icon: 'el-icon-message' },
    children: [
      {
        path: 'repair',
        name: 'Repair1',
        component: () => import('@/views/property/repair/index'),
        meta: { title: '报修信息', icon: 'el-icon-postcard' }
      },
      {
        path: 'repair',
        name: 'Repair1',
        component: () => import('@/views/property/repair/index'),
        meta: { title: '报修人员', icon: 'form' }
      }
    ]
  },
  {
    path: 'external-link',
    component: Layout,
    children: [
      {
        path: 'https://panjiachen.github.io/vue-element-admin-site/#/',
        meta: { title: 'External Link', icon: 'link' }
      }
    ]
  },

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () =>
  new Router({
    // mode: 'history', // require service support
    scrollBehavior: () => ({ y: 0 }),
    routes: constantRoutes
  })

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
